<template>
  <div class="account_period_setting">
    <div class="header_title">
      <span>账期设置列表</span>
    </div>
    <div class="add_zq" v-if="isauth('payment_day_edit')">
      <el-button @click="addzq()" type="primary" size="mini" icon="el-icon-plus">新增账期</el-button>
    </div>
    <div class="listable">
      <el-table
        v-loading="dataListLoading"
        :data="data1"
        style="width: 100%"
        :header-cell-style="headFirst"
        :cell-style="(res) => headFirst_col(res, [])"
      >
        <el-table-column prop="paymentName" label="账期名称"></el-table-column>
        <el-table-column prop="startTime" label="开始时间"></el-table-column>
        <el-table-column prop="endTime" label="结束时间"></el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <div>{{ scope.row.status | statusfilter }}</div>
          </template>
        </el-table-column>
        <el-table-column width="300" label="操作" v-if="isauth('payment_day_edit')">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="UpdateHandle(scope.row)">修改</el-button>
            <el-button type="text" size="mini" @click="deletehandle(scope.row)" style="color:red">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChangepage"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="recordCount"
        ></el-pagination>
      </div>
    </div>
    <!-- 新增编辑弹出 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="consumepaymentpage"
    ></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './account-period-setting-add-update'

export default {
  data() {
    return {
      addOrUpdateVisible: false,
      dataListLoading: false,
      data1: [],
      pageSize: 10,
      pageNum: 1,
      searchInfo: {},
      recordCount: 0,
      currentPage: 1
    }
  },
  components: {
    AddOrUpdate
  },
  mounted() {
    this.consumepaymentpage()
  },
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid
      }
    }
  },
  filters: {
    statusfilter: function(status) {
      if (status == 0) {
        return '未结算'
      }
      if (status == 1) {
        return '已结算'
      }
    }
  },
  methods: {
    addzq() {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.addinit()
      })
    },
    //账期分页列表查询
    consumepaymentpage() {
      this.dataListLoading = true
      this.searchInfo.unitGuid = this.changeschoolid
      this.$http({
        url: this.$http.adornUrl('/terminal/consume/payment-day-page'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: this.searchInfo
          },
          messageType: 0
        })
      }).then(({ data }) => {
        this.dataListLoading = false
        console.log(data)
        if (data.messageCode == 200) {
          this.data1 = data.messageContent.data
          this.recordCount = data.messageContent.recordCount
          this.currentPage = data.messageContent.pageNum
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //修改账期
    UpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.eidtinit(row)
      })
    },
    //删除
    deletehandle(row) {
      this.$confirm('此操作将永久删除该账期, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          console.log(row)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    //分页
    handleSizeChange(val) {
      this.pageSize = val
      this.consumepaymentpage()
    },
    handleCurrentChangepage(val) {
      this.pageNum = val
      this.consumepaymentpage()
    }
  }
}
</script>

<style lang="scss" scoped>
.account_period_setting {
  padding: 10px;
  .header_title {
    // text-indent: 22px;
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #e5e9f2;
    color: #909399;
  }
  .add_zq {
    border-bottom: 1px solid #e5e9f2;
    // text-indent: 20px;
    height: 50px;
    line-height: 50px;
  }
  .page {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
